package br.com.nrti.still.service;

import java.util.Timer;
import java.util.TimerTask;

import br.com.nrti.still.eventos.Alarme;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class DisparaEvento extends Service {

	private final IBinder mBinder = new EventoBinder();
	private static Timer timer = new Timer();
	private static final int INTERVALO_VERIFICACAO = 1000;

	public class EventoBinder extends Binder {
		DisparaEvento getService() {
			return DisparaEvento.this;
		}
	}

	@Override
	public IBinder onBind(Intent arg0) {
		return mBinder;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		iniciar();
	}

	private void iniciar() {
		Alarme.inicializar(getApplicationContext());
		timer.scheduleAtFixedRate(new mainTask(), 0, INTERVALO_VERIFICACAO);
	}

	private class mainTask extends TimerTask {
		public void run() {
			Alarme.setMuteOn();
		}
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		timer.cancel();
		timer.purge();
	}

}
